@using EventHub.Organizations
@model EventHub.Organizations.OrganizationProfileDto
@inject IOrganizationAppService OrganizationAppService

@{
    PlanInfoDefinitionDto currentPlanInfo = null;
    if (Model is not null)
    {
        var planInfos = await OrganizationAppService.GetPlanInfosAsync();
        currentPlanInfo = planInfos.SingleOrDefault(x => x.PlanType == Model.PlanType);
    }
}

@if (Model is not null && currentPlanInfo is not null)
{
    <abp-container class="mt-4">
        <abp-row>
            @if (Model.PlanType != OrganizationPlanType.Free && currentPlanInfo.IsActive && currentPlanInfo.IsExtendable && Model.PaidEnrollmentEndDate!.Value.IsBetween(DateTime.Now, DateTime.Now.AddMonths(currentPlanInfo.OnePaidEnrollmentPeriodAsMonth!.Value - currentPlanInfo.CanBeExtendedAfterHowManyMonths!.Value)))
            {
                <span class="mb-2 ms-5 text-center strong">@Model.PlanType end date: @Model.PaidEnrollmentEndDate!.Value.ToShortDateString()</span>
            }
            <abp-column>
                <a href="/organization/edit/@Model.Name" class="btn btn-success text-white">Edit</a>
            </abp-column>
            <abp-column size="_9">
                @if (currentPlanInfo.IsActive)
                {
                    @if (Model.PlanType != OrganizationPlanType.Free)
                    {
                        @if (currentPlanInfo.IsExtendable && Model.PaidEnrollmentEndDate!.Value.IsBetween(DateTime.Now, DateTime.Now.AddMonths(currentPlanInfo.OnePaidEnrollmentPeriodAsMonth!.Value - currentPlanInfo.CanBeExtendedAfterHowManyMonths!.Value)))
                        {
                            <div class="d-grid gap-2">
                                <a href="@Url.Page("/Pricing", new { organizationName = Model.Name })" class="btn btn-info">
                                    <i class="fas fa-crown me-2"></i> Extend Now
                                </a>
                            </div>
                        }
                        else
                        {
                            <div class="d-grid gap-2">
                                <button class="btn btn-info">
                                    <span class="mt-2">@Model.PlanType end date: @Model.PaidEnrollmentEndDate!.Value.ToShortDateString()</span>
                                </button>
                            </div>
                        }
                    }
                    else
                    {
                        <div class="d-grid gap-2">
                            <a href="@Url.Page("/Pricing", new { organizationName = Model.Name })" class="btn btn-info">
                                <i class="fas fa-crown me-2"></i> Upgrade your organization
                            </a>
                        </div>
                    }
                }
                else
                {
                    <abp-card class="text-center">
                        <abp-card-body>
                            <span>@Model.PlanType end date: @Model.PaidEnrollmentEndDate!.Value.ToShortDateString()</span>
                        </abp-card-body>
                    </abp-card>
                }
            </abp-column>
        </abp-row>
    </abp-container>
}
